import 'dart:convert';

import 'package:qunaimedical/models/doctor_account.dart';

class Doctor {
  String id,
      doctorId,
      office,
      professionalName,
      doctorName,
      sectionName,
      username,
      fullname,
      avatar,
      skilled,
      doctorRole,
      // 是否收藏 0：否 1：是
      whetherAppointed,
      // 是否被预约 0：否 1：是
      whetherSelected;

  DoctorInfo doctorAccount;

  List<DoctorInfo> doctorInfoList;

  List<String> skilleds;

  /// 是否选中
  bool selected;

  int appointedNum;

  Doctor({
    this.id,
    this.doctorId,
    this.office,
    this.professionalName,
    this.doctorName,
    this.sectionName,
    this.username,
    this.fullname,
    this.avatar,
    this.skilled,
    this.skilleds,
    this.doctorAccount,
    this.selected,
    this.doctorInfoList,
    this.appointedNum,
    this.doctorRole,
    this.whetherAppointed,
    this.whetherSelected,
  });

  factory Doctor.fromJson(Map<String, dynamic> data) {
    return Doctor(
        id: data['id'],
        doctorId: data['doctorId'],
        office: data['office'],
        professionalName: data['professionalName'],
        doctorName: data['doctorName'],
        sectionName: data['sectionName'],
        username: data['username'],
        fullname: data['fullname'],
        avatar: data['avatar'],
        skilled: data['skilled'],
        doctorRole: data['doctorRole'],
        whetherAppointed: data['whetherAppointed']?.toString(),
        whetherSelected: data['whetherSelected'] == null
            ? '0'
            : data['whetherSelected']?.toString(),
        appointedNum: data['appointedNum'] == null || data['appointedNum'] == ''
            ? 0
            : data['appointedNum'],
        doctorAccount: data['doctorAccount'] == null
            ? null
            : DoctorInfo.fromJson(data['doctorAccount']),
        skilleds: data.containsKey('skilleds') && data['skilleds'] != ''
            ? List.from(data['skilleds'])
            : null,
        doctorInfoList: !data.containsKey('doctorInfoList')
            ? []
            : (data['doctorInfoList'] as List)
                .map((e) => DoctorInfo.fromJson(e))
                .toList());
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'doctorId': doctorId,
      'office': office,
      'professionalName': professionalName,
      'doctorName': doctorName,
      'sectionName': sectionName,
      'username': username,
      'fullname': fullname,
      'avatar': avatar,
      'skilled': skilled,
      'skilleds': skilleds,
      'doctorInfoList': doctorInfoList,
      'appointedNum': appointedNum,
      'doctorRole': doctorRole,
      'whetherAppointed': whetherAppointed,
    };
  }

  @override
  String toString() {
    return json.encode(toMap());
  }
}
